/**
 * 违章审核记录 编辑页
 *
 * 作者 Wanghw
 * 日期 2024-08-14 10:38:38
 */
layui.use(['jquery','febs','laydate', 'form', 'validate','commonJS'], function () {
    var $ = layui.$,
        form = layui.form,
        laydate = layui.laydate,
        febs = layui.febs,
        $view = $('#peccancyChargeOffilne-edit'),
        $addBtn = $view.find("#addBtn"),
        validate = layui.validate;

    form.verify(validate);
    initDate();
    initFormValue();
    form.render();

    function initFormValue() {
        if (chargeUser) {
            form.val("peccancyChargeOffilne-edit-form", {
                "chargeUserId": chargeUser.userId,
                "chargeRealName": chargeUser.userName,
            });
        }
        form.val("peccancyChargeOffilne-edit-form", {
            "informationId": POPUP_DATA.informationId
        });

    }
    function initDate() {
        //初始化日期控件
        laydate.render({
            elem: '#febs-form-group-date',
            type: 'datetime',
            // value: new Date(),
            // format:'yyyy-MM-dd HH:mm:ss',
            // isInitValue: true,
            btns:['now','confirm']
        })
        form.render();

    }

    function addOrUpdate(data) {
        febs.modal.confirm('线下缴款提示', '是否提交缴款信息？', function () {
            febs.postArray(ctx + 'peccancyChargeRecord/pay', data, function () {
                layer.closeAll();
                febs.alert.success('缴款成功');
                $('#febs-peccancyChargeRecord').find('#query').trigger('click');
            });
        });

    }

    form.on('submit(peccancyChargeOffilne-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    $addBtn.on('click', function () {
        febs.modal.open('选择用户', 'common/user', {
            btn: ['确认','关闭'],
            area: $(window).width() <= 750 ? ['95%', '85%']: ['90%', '85%'],
            data:{
                tenantId:$('#tenantId').val(),
                multiple:false,
            },
            yes: function (index, layero) {
                let selectData = null
                if(typeof getSelectData  === 'function'){
                    selectData = getSelectData()
                }
                temp = selectData;
                // console.log("获得的人员"+JSON.stringify(temp))
                // debugger

                if(selectData){
                    $view.find('input[name="chargeUserId"]').val(selectData.userId);
                    $view.find('input[name="chargeRealName"]').val(selectData.uname);
                    layer.close(index);
                }

            },
            btn2: function (index, layero) {
                layer.close(index);
                return false;
            }
        });

    });


});